<?php
namespace app\admin\controller;

class TplNormal extends Base{
    //
    protected function initialize() {
        parent::initialize();
        $this->model = 'TplNormal';
    }
    //
    protected function _before_index(){
        $thead = [
            'tnid' => 'TNID',
            'tname' => '模版名称',
            'tnno' => '模版路径',
            'img' => '预览图片',
            'used' => '可用状态',
            'addtime' =>'创建时间',
        ];
        $this->assign('thead', $thead);
    }
    //
    protected function _filter($map){
        return $map;
    }
    //
    protected function _after_list($list){
        foreach($list as $key => $row){
            $list[$key]['tnno'] = $row['tnno'] ? '/tpl/nm/'.$row['tnno'] : '';
            $list[$key]['used'] = $row['used'] == 1 ? '在用' : '未用';
            $list[$key]['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
        }
        return $list;
    }
    //
    protected function _before_add(){}
    //
    protected function _before_insert($data){
        $data['addtime'] = time();
        return $data;
    }
    //
    protected function _after_add($data, $id){
        $this->log(['pk' => 'tnid', 'value' => $id], $data);
    }
    //
    protected function _before_edit(){}
    //
    protected function _filter_edit($list){
        return $list;
    }
    //
    protected function _before_save($data){
        return $data;
    }
    //
    protected function _after_edit($data){
        $this->log(['pk' => 'tnid', 'value' => $data['tnid']], $data);
    }
    //
    protected function _filter_del(){
        return [1,2];
    }
    //
    protected function _after_del($rows){
        $logs = [];
        foreach($rows as $row){
            $logs[] = ['pk' => 'tnid', 'value' => $row['tnid'], 'row' => $row];
        }
        $this->logAll($logs);
    }
}